/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.bs.views;

import com.bs.beans.Conta;
import java.util.ArrayList;
import org.jdesktop.observablecollections.ObservableCollections;

/**
 *
 * @author Bone
 */
public class ContaView extends javax.swing.JPanel {

    /**
     * Creates new form BancoDetalhe
     */
    public ContaView() {
        initComponents();
        contaGridController.getParametros().add(descricaoPesquisa);
        contaGridController.getParametros().add(bancoPesquisa);
    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {
        bindingGroup = new org.jdesktop.beansbinding.BindingGroup();

        entityManager = new com.bs.persistencia.EntityManager();
        list =  ObservableCollections.observableList(new ArrayList<Conta>());
        contaGridController = new com.bs.controllers.ContaGridController<com.bs.beans.Conta>();
        conta = new com.bs.beans.Conta();
        jScrollPane1 = new javax.swing.JScrollPane();
        contasTable = new javax.swing.JTable();
        jPanel1 = new javax.swing.JPanel();
        descricaoPesquisa = new com.bs.pesquisaView.PesquisaTexto();
        bancoPesquisa = new com.bs.pesquisaView.PesquisaObjeto();
        limiteRegistrosLabel = new javax.swing.JLabel();
        limiteRegistrosField = new com.bs.extensoesSwing.CampoNumericoInteiro();
        filtrarButton = new com.bs.extensoesSwing.FiltrarRegistroGridButton();
        alterarRegistroGridButton = new com.bs.extensoesSwing.AlterarRegistroGridButton();
        atualizarGridButton = new com.bs.extensoesSwing.AtualizarGridButton();
        novoRegistroGridButton = new com.bs.extensoesSwing.NovoRegistroGridButton();
        tituloFormulario = new com.bs.extensoesSwing.TituloFormulario();
        jSeparator1 = new javax.swing.JSeparator();
        excluirRegistroGridButton = new com.bs.extensoesSwing.ExcluirRegistroGridButton();

        contaGridController.setClasse(conta);
        contaGridController.setEntityManager(entityManager);
        contaGridController.setLimiteRegistros(30);
        contaGridController.setLista(list);

        org.jdesktop.beansbinding.Binding binding = org.jdesktop.beansbinding.Bindings.createAutoBinding(org.jdesktop.beansbinding.AutoBinding.UpdateStrategy.READ_WRITE, contasTable, org.jdesktop.beansbinding.ELProperty.create("${selectedElement}"), contaGridController, org.jdesktop.beansbinding.BeanProperty.create("beanSelecionado"));
        binding.setSourceNullValue(new Conta());
        binding.setSourceUnreadableValue(null);
        bindingGroup.addBinding(binding);
        binding = org.jdesktop.beansbinding.Bindings.createAutoBinding(org.jdesktop.beansbinding.AutoBinding.UpdateStrategy.READ_WRITE, contasTable, org.jdesktop.beansbinding.ELProperty.create("${selectedElement.id}"), contaGridController, org.jdesktop.beansbinding.BeanProperty.create("idBeanSelecionado"));
        binding.setSourceNullValue(null);
        binding.setSourceUnreadableValue(null);
        bindingGroup.addBinding(binding);

        setName("Contas"); // NOI18N

        contasTable.setAutoResizeMode(javax.swing.JTable.AUTO_RESIZE_OFF);
        contasTable.setSelectionMode(javax.swing.ListSelectionModel.SINGLE_SELECTION);

        org.jdesktop.swingbinding.JTableBinding jTableBinding = org.jdesktop.swingbinding.SwingBindings.createJTableBinding(org.jdesktop.beansbinding.AutoBinding.UpdateStrategy.READ_WRITE, list, contasTable);
        org.jdesktop.swingbinding.JTableBinding.ColumnBinding columnBinding = jTableBinding.addColumnBinding(org.jdesktop.beansbinding.ELProperty.create("${descricao}"));
        columnBinding.setColumnName("Descricao");
        columnBinding.setColumnClass(String.class);
        columnBinding.setEditable(false);
        columnBinding = jTableBinding.addColumnBinding(org.jdesktop.beansbinding.ELProperty.create("${banco.nomeBanco}"));
        columnBinding.setColumnName("Banco");
        columnBinding.setColumnClass(String.class);
        columnBinding.setEditable(false);
        columnBinding = jTableBinding.addColumnBinding(org.jdesktop.beansbinding.ELProperty.create("${agencia}"));
        columnBinding.setColumnName("Agencia");
        columnBinding.setColumnClass(Integer.class);
        columnBinding.setEditable(false);
        columnBinding = jTableBinding.addColumnBinding(org.jdesktop.beansbinding.ELProperty.create("${conta}"));
        columnBinding.setColumnName("Conta");
        columnBinding.setColumnClass(Integer.class);
        columnBinding.setEditable(false);
        columnBinding = jTableBinding.addColumnBinding(org.jdesktop.beansbinding.ELProperty.create("${saldo}"));
        columnBinding.setColumnName("Saldo");
        columnBinding.setColumnClass(java.math.BigDecimal.class);
        columnBinding.setEditable(false);
        bindingGroup.addBinding(jTableBinding);
        jTableBinding.bind();
        jScrollPane1.setViewportView(contasTable);
        contasTable.getColumnModel().getColumn(0).setPreferredWidth(200);
        contasTable.getColumnModel().getColumn(1).setPreferredWidth(150);
        contasTable.getColumnModel().getColumn(2).setPreferredWidth(100);
        contasTable.getColumnModel().getColumn(3).setPreferredWidth(100);
        contasTable.getColumnModel().getColumn(4).setPreferredWidth(100);

        jPanel1.setBorder(javax.swing.BorderFactory.createTitledBorder("Filtro"));

        descricaoPesquisa.setCampo("descricao");
        descricaoPesquisa.setLegenda("Descrição:");

        bancoPesquisa.setCampo("banco");
        bancoPesquisa.setCampoPesquisa("nomeBanco");
        bancoPesquisa.setConsulta("SELECT b FROM Banco b WHERE b.nomeBanco LIKE :parametro");
        bancoPesquisa.setLegenda("Banco:");

        limiteRegistrosLabel.setText("Limite de registros:");

        binding = org.jdesktop.beansbinding.Bindings.createAutoBinding(org.jdesktop.beansbinding.AutoBinding.UpdateStrategy.READ_WRITE, contaGridController, org.jdesktop.beansbinding.ELProperty.create("${limiteRegistros}"), limiteRegistrosField, org.jdesktop.beansbinding.BeanProperty.create("text"));
        binding.setSourceUnreadableValue(null);
        bindingGroup.addBinding(binding);

        filtrarButton.setController(contaGridController);

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(descricaoPesquisa, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addComponent(bancoPesquisa, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(filtrarButton, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addComponent(limiteRegistrosLabel)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(limiteRegistrosField, javax.swing.GroupLayout.PREFERRED_SIZE, 90, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addContainerGap(156, Short.MAX_VALUE))
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(limiteRegistrosLabel)
                    .addComponent(limiteRegistrosField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(descricaoPesquisa, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(bancoPesquisa, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(filtrarButton, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap(12, Short.MAX_VALUE))
        );

        alterarRegistroGridButton.setController(contaGridController);

        binding = org.jdesktop.beansbinding.Bindings.createAutoBinding(org.jdesktop.beansbinding.AutoBinding.UpdateStrategy.READ_WRITE, contasTable, org.jdesktop.beansbinding.ELProperty.create("${selectedElement != null}"), alterarRegistroGridButton, org.jdesktop.beansbinding.BeanProperty.create("enabled"));
        bindingGroup.addBinding(binding);

        atualizarGridButton.setController(contaGridController);

        novoRegistroGridButton.setController(contaGridController);

        tituloFormulario.setTitulo("Contas bancárias");

        excluirRegistroGridButton.setController(contaGridController);

        binding = org.jdesktop.beansbinding.Bindings.createAutoBinding(org.jdesktop.beansbinding.AutoBinding.UpdateStrategy.READ_WRITE, contasTable, org.jdesktop.beansbinding.ELProperty.create("${selectedElement != null}"), excluirRegistroGridButton, org.jdesktop.beansbinding.BeanProperty.create("enabled"));
        bindingGroup.addBinding(binding);

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
        this.setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(tituloFormulario, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addGroup(layout.createSequentialGroup()
                        .addGap(0, 0, Short.MAX_VALUE)
                        .addComponent(novoRegistroGridButton, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(alterarRegistroGridButton, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(excluirRegistroGridButton, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(2, 2, 2)
                        .addComponent(atualizarGridButton, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addComponent(jScrollPane1, javax.swing.GroupLayout.Alignment.LEADING))
                .addContainerGap())
            .addComponent(jSeparator1)
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addComponent(tituloFormulario, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 202, Short.MAX_VALUE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jSeparator1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                    .addComponent(atualizarGridButton, javax.swing.GroupLayout.DEFAULT_SIZE, 45, Short.MAX_VALUE)
                    .addComponent(alterarRegistroGridButton, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(novoRegistroGridButton, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(excluirRegistroGridButton, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                .addContainerGap())
        );

        bindingGroup.bind();
    }// </editor-fold>//GEN-END:initComponents
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private com.bs.extensoesSwing.AlterarRegistroGridButton alterarRegistroGridButton;
    private com.bs.extensoesSwing.AtualizarGridButton atualizarGridButton;
    private com.bs.pesquisaView.PesquisaObjeto bancoPesquisa;
    private com.bs.beans.Conta conta;
    private com.bs.controllers.ContaGridController<com.bs.beans.Conta> contaGridController;
    private javax.swing.JTable contasTable;
    private com.bs.pesquisaView.PesquisaTexto descricaoPesquisa;
    private com.bs.persistencia.EntityManager entityManager;
    private com.bs.extensoesSwing.ExcluirRegistroGridButton excluirRegistroGridButton;
    private com.bs.extensoesSwing.FiltrarRegistroGridButton filtrarButton;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JSeparator jSeparator1;
    private com.bs.extensoesSwing.CampoNumericoInteiro limiteRegistrosField;
    private javax.swing.JLabel limiteRegistrosLabel;
    private java.util.List<Conta> list;
    private com.bs.extensoesSwing.NovoRegistroGridButton novoRegistroGridButton;
    private com.bs.extensoesSwing.TituloFormulario tituloFormulario;
    private org.jdesktop.beansbinding.BindingGroup bindingGroup;
    // End of variables declaration//GEN-END:variables
}
